<template>
  <div class="bargain-buy-set">
    <div class="bargain-buy-set-header">
      <div class="container-header group">
        <Input
            class="start"
            v-model.trim="storeName"
            placeholder="请输入例外名称"
            @on-enter="getData">
        </Input>
        <Button type="primary" icon="ios-search" class="btn-search" @click="getData(1)"></Button>
      </div>
      <Button class="mt mr"  size="large" type="primary" @click="onEditSize(1)">添加规格</Button>
    </div>
    <homeTable
      :translate="400"
      :list="list"
      @getData="getData"
      @onPageSizeChange="onPageSizeChange"
      @onPageChange="onPageChange"
    />
    <addSize @complete="getData" ref="addSize"></addSize>
  </div>
</template>
<script>
import listData from "./SizeListData";
import homeTable from '~/homeTable'
import addSize from "./addSizeItem";
export default {
  components: {
    homeTable,
    addSize
  },
  data() {
    return {
      id: this.$route.query.id,
      list: listData,
      storeName: ''
    }
  },
  mounted() {
    if (this.$route.query.id) this.getData()
    this.list.currentPage = 1
    this.$bus.$on('onEditSize', this.onEditSize)
    this.$bus.$on('onDel', this.onDel)
  },
  methods: {
    getData(type) {
      this.list.status = 'loading'
      if (type == 1)  this.list.currentPage = 1
      let param = {
        activityId: this.$route.query.id,
        size: this.list.pageSize,
        current: this.list.currentPage,
        keyword: this.storeName
      }
      this.$ajaxPost(`/activity/factory_info/sku/exceptional/page`, param).then(res => {
        this.list.status = 'pass'
        this.list.data = res.records
        this.list.totalItem = Number(res.total)
      }).catch(() => {  
        this.list.status = "error"
      })
    },
    onPageChange(number) {
      this.list.currentPage = number;
      this.getData()
    },
    onPageSizeChange(pageSize) {
      this.list.currentPage = 1;
      this.list.pageSize = pageSize;
      this.getData()
    },
    onEditSize(row, index) {
      this.$refs.addSize.setShowMotal(row, index)
    },
    onDel(row) {
      this.$Modal.confirm({
        title: "确认",
        content: `你确定要删除${row.item.storeName}例外规格`,
        onOk: () => {
          this.$jsonPost(`/activity/factory_info/sku/exceptional/delete/${row.item.id}`).then(res => {
            this.getData()
          })
        }
      })
    }
  }
}
</script>